#!/bin/bash -e

# determine directory containing this script
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  SOURCE="$(readlink "$SOURCE")"
  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

$DIR/allocate-ports $(cat <<EOF
JBOSS_MANAGEMENT_NATIVE_PORT
JBOSS_MANAGEMENT_HTTP_PORT
JBOSS_MANAGEMENT_HTTPS_PORT
JBOSS_AJP_PORT
JBOSS_HTTP_PORT
JBOSS_HTTPS_PORT
JBOSS_OSGI_PORT
JBOSS_REMOTING_PORT
JBOSS_TXN_RECOVERY_PORT
JBOSS_TXN_STATUS_PORT
MYSQL_PORT
MAIL_PORT
EOF
)
# we might want these in future:
# JBOSS_IIOP_PORT
# JBOSS_IIOP_SSL_PORT
